<?php

if (! defined ( 'BASEPATH' ))exit ( 'No direct script access allowed' );

class Index extends CI_Controller {
	function __construct() {
		parent::__construct ();
	}
	
	public function index(){
		$this->load->model('Rhome');
		$data['category'] = $this->Rhome->get_categories();
		$data['page_title']='9iria爱睿电子书城';
		$this->load->view('header',$data);
		$this->load->view('index');
		$this->load->view('footer');
	}
	
	public function category(){
		$this->load->model('Rhome');
		$data['page_title']='9iria爱睿电子书城';
		$data['category'] = $this->Rhome->get_categories();
		$data['books'] = $this->Rhome->get_books_list($this->uri->segment(3));
		$data['category_name'] = $this->Rhome->get_categores_name($this->uri->segment(3));
		$this->load->view('header',$data);
		$this->load->view('category');
		$this->load->view('footer');
	}
	
	public function book(){
		$this->load->model('Rhome');
		$this->load->helper('form');
		$data['page_title']='9iria爱睿电子书城';
		$data['get_comments'] = $this->Rhome->get_comment($this->uri->segment(3));
		$data['book_cotent'] = $this->Rhome->get_book_content($this->uri->segment(3));
		$this->load->view('header',$data);
		$this->load->view('book');
		$this->load->view('footer');
	}
	
	public function comment_ok(){
//		$this->load->helper('date');
		if ($this->input->post('submit')){
			$data = array(
			'comment_content' => $this->input->post('comment_content'),
			'comment_user_id' => $this->input->post('user_id'),
			'comment_book_id' => $this->input->post('book_id')
			);
			$this->load->model('Rhome');
			$query = $this->Rhome->insert_comment($data);
			if ($query){
				 redirect('index/book/'.$this->input->post('book_id'));
			}
		}
	}
}

?>